/*
 * Exploder
 * 
 * Tero Pyylampi (218437), Jussi Tuurinkoski (211594)
 *
 * Abstract base class for all the construction elements in the game
 */

#ifndef GAMECONSTRUCTIONELEMENT_H
#define GAMECONSTRUCTIONELEMENT_H

#include "../GamePhysicObject.h"
#include "../../../../Common.h"

class GameCamera;

class GameConstructionElement : public GamePhysicObject {
public:
	// default constructor
	GameConstructionElement( b2World *world, cocos2d::CCLayer *layer, GameCamera *camera, bool editingMode, ElementType properties );
	// default destructor
	virtual ~GameConstructionElement();

	// update function
	virtual void update( cocos2d::ccTime dt ) = 0;

	// game mode related functions
	
	// apply explosion force, the object itself should decide whether to break or not
	virtual void applyExplosionToElements( b2Vec2 sourcePos, float force ) = 0;
	// change object sprite to broken
	virtual void changeSpriteToBroken() = 0;
	// break object into pieces
	virtual void breakObject() = 0;
	// object takes damage as a result of a collision
	virtual void takeDamage( float damage, b2Body *bodyTakingDamage );

	// get the information of this object
	virtual bool isThisObjectPreventingVictory();
	virtual bool isThisObjectBrokenOrMoved();

	// editing mode related functions
	
	// activate or deactivate object
	void setObjectActive( bool active );
	// whether this object is active
	bool isObjectActive();

	// menu related items, SHOULD NOT BE CALLED OUTSIDE THIS CLASS
	
	// remove item
	void removeItem( cocos2d::CCObject *pSender );
	// rotate item
	void rotateItem( cocos2d::CCObject *pSender );
	// switch block state
	void switchState( cocos2d::CCObject *pSender );

	// get element state
	ElementType getElementStateType();

protected:
	// layer to be used
	cocos2d::CCLayer *mLayer;
	// pointer to the game camera
	GameCamera *mGameCamera;

	// normal sprite
	cocos2d::CCSprite *mIntactSprite;
	// broken sprites
	cocos2d::CCSprite *mBrokenSprites[ 4 ];

	// state of this element
	ElementType mElementType;
	// whether the editing mode is on
	bool mObjectInEditingMode;

	// game mode related variables

	// whether this object has broke
	bool mObjectBroken;
	// durability of this object & object's max durability
	float mObjectDurabilityLeft;
	float mObjectMaxDurability;
	// initial position of the object
	b2Vec2 mInitialPosition;
	// broken part durabilities
	float mBrokenPartDurabilities[ 4 ];

	// set sprite colours to red
	void setRedSpriteColors();
	// remove a single broken element from game
	void removeBrokenElementFromGame( int element );

	// editing mode related variables

	// whether this object is currently active
	bool mCurrentlyActive;
	// settings included when in editing mode and this object is active
	cocos2d::CCMenu *mEditModeActiveMenu;
	
	// helper function to create menu items
	void createEditMenuItems();
};

#endif